import wx

class MyFrame(wx.Frame):
    # 初始化方法
    def __init__(self, parent, id):
        wx.Frame.__init__(self, parent, id, title='用户登录', size=(400,240))
        # 创建面板
        panel = wx.Panel(self)
        # 添加文本和输入框
        self.title = wx.StaticText(panel, label='请输入用户名和密码', pos=(140, 20))
        self.lable_user = wx.StaticText(panel, label='用户名:', pos=(50, 50))
        self.text_user = wx.TextCtrl(panel, pos=(100, 50), size=(225, 25), style=wx.TE_LEFT)
        self.lable_pwd = wx.StaticText(panel, label='密码:', pos=(50, 90))
        self.text_pwd = wx.TextCtrl(panel, pos=(100, 90), size=(225, 25), style=wx.TE_LEFT)

        # 两个按钮
        self.bt_login = wx.Button(panel, label='登录', pos=(105, 130))
        self.bt_cancel = wx.Button(panel, label='取消', pos=(195, 130))

        # 为按钮绑定单击事件
        self.bt_login.Bind(wx.EVT_BUTTON, self.OnClickLogin)
        self.bt_cancel.Bind(wx.EVT_BUTTON, self.OnClickCancel)

    def OnClickLogin(self, event):
        message = ''
        username = self.text_user.GetValue()  # 获取用户名
        password = self.text_pwd.GetValue()  # 获取密码
        if username == '' or password == '':
            message = '用户名或密码不能为空'
        elif username == 'duiduo' and password == '123':
            message = '登录成功'
        else:
            message = '用户名或密码不正确'

        # 弹框
        wx.MessageBox(message)


    def OnClickCancel(self, event):
        self.text_user.SetValue('')  # 清空输入的用户名
        self.text_pwd.SetValue('')  # 清空输入的密码


# 以主函数程序
if __name__ == '__main__':
    app = wx.App() # 启动应用
    frame = MyFrame(parent=None, id=-1)
    frame.Show()
    app.MainLoop()
